package org.net5ijy.cloud.plugin.feign.core;


import com.github.javaparser.JavaParser;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.expr.ClassExpr;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import jdk.internal.org.objectweb.asm.MethodVisitor;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

public class MainMethodAccess {

    public static void main(String[] args) throws FileNotFoundException {
        // creates an input stream for the file to be parsed
        FileInputStream in = new FileInputStream("/Users/spafka/Desktop/github/feign-generator/feign-generator-server-demo/src/main/java/org/net5ijy/cloud/feign/demo/controller/IndexController.java");

        CompilationUnit cu = StaticJavaParser.parse(in);

        // visit and print the methods names
        List<String> res=new ArrayList<>();
        new MethodVisitor().visit(cu,res );
    }

    /**
     * Simple visitor implementation for visiting MethodDeclaration nodes.
     */
    private static class MethodVisitor extends VoidVisitorAdapter {
        @Override
        public void visit(ClassExpr n, Object arg) {
            super.visit(n, arg);
        }

        @Override
        public void visit(ClassOrInterfaceDeclaration n, Object arg) {
            super.visit(n, arg);
        }

        @Override
        public void visit(ClassOrInterfaceType n, Object arg) {
            super.visit(n, arg);
        }

        @Override
        public void visit(MethodDeclaration n, Object arg) {
            // here you can access the attributes of the method.
            // this method will be called for all methods in this
            // CompilationUnit, including inner class methods
            System.out.println(n.getName());



        }






    }

}